#include    "loco-crane.h"

#include    <QLibrary>

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
LocoCrane::LocoCrane(QObject *parent) : BrakeDevice(parent)
  , pFL(0.0)
  , pBC(0.0)
  , Qvr(0.0)
  , Qbc(0.0)
  , pos(0.0)
  , is_release(0.0)
{

}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
LocoCrane::~LocoCrane()
{

}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::setFeedlinePressure(double pFL)
{
    this->pFL = pFL;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::setBrakeCylinderPressure(double pBC)
{
    this->pBC = pBC;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::setAirDistributorFlow(double Qvr)
{
    this->Qvr = Qvr;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::setHandlePosition(double pos)
{
    this->pos = pos;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
double LocoCrane::getBrakeCylinderFlow() const
{
    return Qbc;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
double LocoCrane::getAirDistribPressure() const
{
    return 0.0;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::release(bool is_release)
{
    this->is_release = static_cast<double>(is_release);
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void LocoCrane::stepSound()
{
    return;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
LocoCrane *loadLocoCrane(QString lib_path)
{
    LocoCrane *crane = nullptr;

    QLibrary lib(lib_path);

    if (lib.load())
    {
        GetLocoCrane getLocoCrane = reinterpret_cast<GetLocoCrane>(lib.resolve("getLocoCrane"));

        if (getLocoCrane)
        {
            crane = getLocoCrane();
        }
    }

    return crane;
}
